function varargout = archui(varargin)
% ARCHUI M-file for archui.fig
%      ARCHUI, by itself, creates a new ARCHUI or raises the existing
%      singleton*.
%
%      H = ARCHUI returns the handle to a new ARCHUI or the handle to
%      the existing singleton*.
%
%      ARCHUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ARCHUI.M with the given input arguments.
%
%      ARCHUI('Property','Value',...) creates a new ARCHUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before archui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to archui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help archui

% Last Modified by GUIDE v2.5 12-Jun-2006 15:45:51

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @archui_OpeningFcn, ...
                   'gui_OutputFcn',  @archui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before archui is made visible.
function archui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to archui (see VARARGIN)

% Choose default command line output for archui
handles.output = hObject;

handles.archs = [];
handles.archdescs = {};

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes archui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = archui_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function txtProgram_Callback(hObject, eventdata, handles)
% hObject    handle to txtProgram (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtProgram as text
%        str2double(get(hObject,'String')) returns contents of txtProgram as a double


% --- Executes during object creation, after setting all properties.
function txtProgram_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtProgram (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtMaster_Callback(hObject, eventdata, handles)
% hObject    handle to txtMaster (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtMaster as text
%        str2double(get(hObject,'String')) returns contents of txtMaster as a double


% --- Executes during object creation, after setting all properties.
function txtMaster_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtMaster (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listNetworkType.
function listNetworkType_Callback(hObject, eventdata, handles)
% hObject    handle to listNetworkType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listNetworkType contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listNetworkType


% --- Executes during object creation, after setting all properties.
function listNetworkType_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listNetworkType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtNetworkBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to txtNetworkBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtNetworkBandwidth as text
%        str2double(get(hObject,'String')) returns contents of txtNetworkBandwidth as a double
set(handles.sldNetworkBandwidth, 'Value', str2num(get(hObject, 'String')))

% --- Executes during object creation, after setting all properties.
function txtNetworkBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtNetworkBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function sldNetworkBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to sldNetworkBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.txtNetworkBandwidth, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldNetworkBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldNetworkBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function sldMemoryBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to sldMemoryBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtMemoryBandwidth, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldMemoryBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldMemoryBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function sldSIMDs_Callback(hObject, eventdata, handles)
% hObject    handle to sldSIMDs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtSIMDs, 'String', num2str(round(get(hObject,'Value'))));


% --- Executes during object creation, after setting all properties.
function sldSIMDs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldSIMDs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function sldSIMDBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to sldSIMDBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtSIMDBandwidth, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldSIMDBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldSIMDBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function sldTrimedias_Callback(hObject, eventdata, handles)
% hObject    handle to sldTrimedias (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtTrimedias, 'String', num2str(round(get(hObject,'Value'))));


% --- Executes during object creation, after setting all properties.
function sldTrimedias_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldTrimedias (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function sldTrimediaBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to sldTrimediaBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtTrimediaBandwidth, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldTrimediaBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldTrimediaBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtMemoryBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to txtMemoryBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtMemoryBandwidth as text
%        str2double(get(hObject,'String')) returns contents of txtMemoryBandwidth as a double
set(handles.sldMemoryBandwidth, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtMemoryBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtMemoryBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtSIMDs_Callback(hObject, eventdata, handles)
% hObject    handle to txtSIMDs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtSIMDs as text
%        str2double(get(hObject,'String')) returns contents of txtSIMDs as a double
set(handles.sldSIMDs, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtSIMDs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtSIMDs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtSIMDBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to txtSIMDBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtSIMDBandwidth as text
%        str2double(get(hObject,'String')) returns contents of txtSIMDBandwidth as a double
set(handles.sldSIMDBandwidth, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtSIMDBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtSIMDBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtTrimedias_Callback(hObject, eventdata, handles)
% hObject    handle to txtTrimedias (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtTrimedias as text
%        str2double(get(hObject,'String')) returns contents of txtTrimedias as a double
set(handles.sldTrimedias, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtTrimedias_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtTrimedias (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtTrimediaBandwidth_Callback(hObject, eventdata, handles)
% hObject    handle to txtTrimediaBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtTrimediaBandwidth as text
%        str2double(get(hObject,'String')) returns contents of txtTrimediaBandwidth as a double
set(handles.sldTrimediaBandwidth, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtTrimediaBandwidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtTrimediaBandwidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in cmdSimulate.
function cmdSimulate_Callback(hObject, eventdata, handles)
% hObject    handle to cmdSimulate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

components = gencomponents(str2num(get(handles.txtMemoryBandwidth, 'String')), ...
			   str2num(get(handles.txtSIMDs, 'String')), ...
			   str2num(get(handles.txtSIMDBandwidth, 'String')), ...
			   str2num(get(handles.txtTrimedias, 'String')), ...
			   str2num(get(handles.txtTrimediaBandwidth, 'String')));

program = get(handles.txtProgram, 'String');
master = get(handles.txtMaster, 'String');
contents = get(handles.listNetworkType,'String');
type = contents{get(handles.listNetworkType, 'Value')};
bandwidth = str2num(get(handles.txtNetworkBandwidth, 'String'));
contents = get(handles.listMapperType,'String');
m = mapper(contents{get(handles.listMapperType, 'Value')}, ...
           get(handles.chkDelay, 'Value'), ...
           str2num(get(handles.txtMaxtime, 'String')), ...
	   str2num(get(handles.txtAvgtime, 'String')), ...
	   str2num(get(handles.txtAvgsqtime, 'String')), ...
	   str2num(get(handles.txtAvgenergy, 'String')), ...
	   str2num(get(handles.txtAvgresources, 'String')));

writexml(arch2xml(master, type, bandwidth, components, m), '/home/wcaarls/src/sc/dse/arch.xml');
[t, e] = simulate(program, '/home/wcaarls/src/sc/dse/arch.xml', ...
		  '/home/wcaarls/src/sc/dse/arch.ps');
c = simcost(type, bandwidth, components);

% COST!!!
ax = handles.axesDesignPoints;
cla(ax);
hold on
if length(handles.archs) > 0
  scatter(ax, handles.archs(:, 1), handles.archs(:, 2), 'bo');
end
handles.archs = [handles.archs; [t c e]];
handles.archdescs{end+1, 1} = ['{{' master ', ' num2str(bandwidth) ...
		    '}, {' get(handles.txtSIMDs, 'String') ...
		    ', ' get(handles.txtSIMDBandwidth, 'String') ...
		    ', ' get(handles.txtTrimedias, 'String') ...
		    ', ' get(handles.txtTrimediaBandwidth, 'String') ...
		    '}, {' m.type ...
		    ', ' num2str(m.delay) ', ' num2str(m.maxtime) ...
		    ', ' num2str(m.avgtime) ', ' num2str(m.avgsqtime)...
		    ', ' num2str(m.avgenergy) ', ' num2str(m.avgresources) '}}'];
handles.archdescs{end, 2} = arch2cmd(master, type, bandwidth, ...
				       components, m);
scatter(ax, t, c, 'rx');
hold off
title([program ' simulation']);
xlabel('Time (s)');
ylabel('Cost (mm^2)');
guidata(gcbo, handles);

!gv /home/wcaarls/src/sc/dse/arch.ps &

% --- Executes on slider movement.
function sldMaxtime_Callback(hObject, eventdata, handles)
% hObject    handle to sldMaxtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtMaxtime, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldMaxtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldMaxtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtMaxtime_Callback(hObject, eventdata, handles)
% hObject    handle to txtMaxtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtMaxtime as text
%        str2double(get(hObject,'String')) returns contents of txtMaxtime as a double
set(handles.sldMaxtime, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtMaxtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtMaxtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function sldAvgtime_Callback(hObject, eventdata, handles)
% hObject    handle to sldAvgtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtAvgtime, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldAvgtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldAvgtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtAvgtime_Callback(hObject, eventdata, handles)
% hObject    handle to txtAvgtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtAvgtime as text
%        str2double(get(hObject,'String')) returns contents of txtAvgtime as a double
set(handles.sldAvgtime, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtAvgtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtAvgtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function sldAvgsqtime_Callback(hObject, eventdata, handles)
% hObject    handle to sldAvgsqtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtAvgsqtime, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldAvgsqtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldAvgsqtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtAvgsqtime_Callback(hObject, eventdata, handles)
% hObject    handle to txtAvgsqtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtAvgsqtime as text
%        str2double(get(hObject,'String')) returns contents of txtAvgsqtime as a double
set(handles.sldAvgsqtime, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtAvgsqtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtAvgsqtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function sldAvgenergy_Callback(hObject, eventdata, handles)
% hObject    handle to sldAvgenergy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtAvgenergy, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldAvgenergy_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldAvgenergy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtAvgenergy_Callback(hObject, eventdata, handles)
% hObject    handle to txtAvgenergy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtAvgenergy as text
%        str2double(get(hObject,'String')) returns contents of txtAvgenergy as a double
set(handles.sldAvgenergy, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtAvgenergy_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtAvgenergy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function sldAvgresources_Callback(hObject, eventdata, handles)
% hObject    handle to sldAvgresources (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.txtAvgresources, 'String', get(hObject,'Value'));


% --- Executes during object creation, after setting all properties.
function sldAvgresources_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sldAvgresources (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function txtAvgresources_Callback(hObject, eventdata, handles)
% hObject    handle to txtAvgresources (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtAvgresources as text
%        str2double(get(hObject,'String')) returns contents of txtAvgresources as a double
set(handles.sldAvgresources, 'Value', str2num(get(hObject, 'String')))


% --- Executes during object creation, after setting all properties.
function txtAvgresources_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtAvgresources (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function axesDesignPoints_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to axesDesignPoints (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pt = get(hObject, 'CurrentPoint');

% Find closest architecture
dist = 99999;
a = 1;
for i = 1:size(handles.archdescs, 1)
  if norm(pt(1, 1:2)-handles.archs(i,1:2)) < dist
    a = i;
    dist = norm(pt(1, 1:2)-handles.archs(i,1:2));
  end
end

display(handles.archdescs{a, 1});
display(handles.archdescs{a, 2});
display(handles.archs(a, :));

if (strcmp(get(gcf, 'SelectionType'), 'extend'))
  program = get(handles.txtProgram, 'String');
  writexml(arch2xml(handles.archdescs{a, 2}), ['/home/wcaarls/src/sc/' ...
		    'dse/arch.xml']);
  [t, e] = simulate(program, '/home/wcaarls/src/sc/dse/arch.xml', ...
		    '/home/wcaarls/src/sc/dse/arch.ps', ...
		    '/home/wcaarls/src/sc/dse/sim.lxt');
		    
  !gtkwave /home/wcaarls/src/sc/dse/sim.lxt /home/wcaarls/src/sc/dse/all.save &
end

if (strcmp(get(gcf, 'SelectionType'), 'alt'))
  program = get(handles.txtProgram, 'String');
  writexml(arch2xml(handles.archdescs{a, 2}), ['/home/wcaarls/src/sc/' ...
		    'dse/arch.xml']);
  [t, e] = simulate(program, '/home/wcaarls/src/sc/dse/arch.xml', ...
		    '/home/wcaarls/src/sc/dse/arch.ps');
  !gv /home/wcaarls/src/sc/dse/arch.ps &
end


% --- Executes on selection change in listMapperType.
function listMapperType_Callback(hObject, eventdata, handles)
% hObject    handle to listMapperType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listMapperType contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listMapperType


% --- Executes during object creation, after setting all properties.
function listMapperType_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listMapperType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in chkDelay.
function chkDelay_Callback(hObject, eventdata, handles)
% hObject    handle to chkDelay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of chkDelay


